package org.redmap.controller
{
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.SyncEvent;
	import flash.external.ExternalInterface;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.*;
	import flash.ui.ContextMenu;
	import flash.ui.Keyboard;
	
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.collections.ArrayList;
	import mx.containers.Canvas;
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.core.DragSource;
	import mx.core.FlexGlobals;
	import mx.core.IUIComponent;
	import mx.core.UIComponent;
	import mx.events.DragEvent;
	import mx.managers.DragManager;

	/**
	 * @flowerModelElementId _8I5zwKxGEd-xV84SKmH0Yw
	 */
	public class DrawingMindMap extends Canvas {
		
		public static const HEIGHT:int = 40;
		public static const MARGIN_BOTTOM:int = 4;
		
		public var lineColor:Number;
		public var fillColor:Number;
		
		[Bindable] public var conn:NetConnection;
		private var so:SharedObject;
		
		public var ballMap:Object = new Object();
		public var labelMap:Object = new Object();
		public  var newShape:MindMapSprite;
		//public var shapeList:ArrayList;
		public var prevItem: MindMapSprite;
		protected var _childs:Object = new Object;
		
		protected var _dataProvider:GraphDataProvider = null;
		protected var _graph: Graph;
		public var g: Graph = new Graph();
		
		protected var drawingSurface:UIComponent;
		private var nodeDragInProgress:Boolean = false;
		private var shapeMove:Boolean = false;
		private var dragCursorStartX:int;
		private var dragCursorStartY:int;
		private var indexPosition:int;
		
		
		public function DrawingMindMap() {
			
			drawingSurface = new UIComponent();
			this.addEventListener("mouseDown", backgroundMouseDownEvent);
			this.addChild(drawingSurface);
			
			
			
			this.addEventListener("preinitialize", myPreinitialize);
			this.addEventListener("creationComplete", myCreationComplete);
			
			this.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

			
			this.verticalScrollPolicy = "off";
			this.horizontalScrollPolicy = "off";
		}
		
		/**
		 * Traps all mouseDown events and adds the mouseMove listener - the offline dragging happens in MindMapSprite.onMouseDown
		 **/
		public function onMouseDown(event:MouseEvent):void{
			nodeDragInProgress=true;
			var selectedSprite:MindMapSprite = MindMapSprite.selectedSprite;
			// move the selected shape into the background
			
			if (selectedSprite != null) {
				var index:int = this.getChildIndex(selectedSprite);
				indexPosition = index;
		    	if (index > 0) {
		       	 this.setChildIndex(selectedSprite, 0);
		    	}
		    }
			trace("selectedsprite id "+selectedSprite._id+ " label "+selectedSprite.label)
			selectedSprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			selectedSprite.removeEventListener(DragEvent.DRAG_ENTER, acceptDrop);
			
			var dragInitiator:IUIComponent = event.currentTarget as IUIComponent;
      
      		// the drag source contains data about what's being dragged
      		var dragSource:DragSource = new DragSource();
      
      		// ask the DragManger to begin the drag
      		DragManager.doDrag( dragInitiator, dragSource, event, null );
      	
			
		}
		
		/**
		 * Traps all mousMove events and updates the RSO property to inform all other connected
		 * clients
		**/
		
		private function onMouseMove(event:MouseEvent):void {
			
			var selectedSprite:MindMapSprite = MindMapSprite.selectedSprite;
		 	so.setProperty(selectedSprite._id, {x:selectedSprite.x, y:selectedSprite.y});
		 	selectedSprite.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		 	refresh();	
		 }
		
		/**
		 * Traps all mouseUp events and sends them to the selected shape.
		 * Useful when you release the mouse while the selected shape is
		 * underneath another one (which prevents the selected shape from
		 * receiving the mouseUp event).
		 */
		public function onMouseUp(evt:MouseEvent):void{
		    var selectedSprite:MindMapSprite = MindMapSprite.selectedSprite;
		    if (selectedSprite != null && selectedSprite.isSelected()) {
			    selectedSprite.onMouseUp(evt);
			    selectedSprite.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			    this.setChildIndex(selectedSprite, indexPosition);
				//trace("refreshChildNodePosition("+selectedSprite._id+");");
			    refreshChildNodePosition(selectedSprite._id);
			   // trace("DrawingMindMap currentTarget: "+evt.currentTarget.toString())
				nodeDragInProgress = false;
				selectedSprite.addEventListener(DragEvent.DRAG_ENTER, acceptDrop);
			}
		}
		
		public function acceptDrop(evt:DragEvent):void{
			var dropTarget:MindMapSprite = evt.currentTarget as MindMapSprite;
			DragManager.acceptDragDrop(dropTarget);
			//trace("acceptDrop: "+evt.currentTarget);
		}
		private function backgroundMouseDownEvent(event: MouseEvent):void  {
			if (nodeDragInProgress){
				return;
			}
			backgroundDragBegin(event);
   			event.stopImmediatePropagation();
   		}
		public function pressEnter(evt:KeyboardEvent):void{
			if (evt.keyCode == Keyboard.ENTER){
				
				var label:String =  MindMapSprite.selectedSprite.label;
				var shape:MindMapSprite = MindMapSprite.selectedSprite;
				//trace("pressEnter: "+label);
				conn.call("changeShape",null,shape._id,shape.color,label);
			}
		}
		
		public function changeColor(shape:MindMapSprite, color:int):void{
				var label:String =  MindMapSprite.selectedSprite.label;
				var shape:MindMapSprite = MindMapSprite.selectedSprite;
				//trace("pressEnter: "+label);
				conn.call("changeShape",null,shape._id,color,shape.label);
			
		}
		
		
		public function dragOver(evt:DragEvent):void{
		
			//trace("dragOver: "+evt.currentTarget);
		}
		
		public function handleDrop(evt:DragEvent):void{
			var dragInitiator:IUIComponent = evt.dragInitiator;
			var dropTarget:IUIComponent = evt.currentTarget as IUIComponent;
			reAllocate(MindMapSprite.selectedSprite,dropTarget as MindMapSprite);
		}
   		
   		private function backgroundDragBegin(event: MouseEvent):void  {
   			this.addEventListener(MouseEvent.MOUSE_MOVE, backgroundDragContinue);
   			dragCursorStartX = event.stageX;
   			dragCursorStartY = event.stageY;

   		}
   		
   		private function backgroundDragContinue(event: MouseEvent):void  {
 			var deltaX: int = event.stageX - dragCursorStartX;
   			var deltaY: int = event.stageY - dragCursorStartY;
  			dragCursorStartX = event.stageX;
   			dragCursorStartY = event.stageY;
   			
   			// apply the delta to all components
   			scroll(deltaX, deltaY);
   	        drawingSurface.invalidateDisplayList();
    		
			refresh();
   		}
  		
 		/** @private */
  		protected function scroll(deltaX: int, deltaY: int): void {
   			var c: Array = this.getChildren();
   			for (var i: int = 1; i < c.length; i++) {
   				var itemView: Object = c[i];
   				if(itemView != drawingSurface) {
   					itemView.x = itemView.x + deltaX;
   					itemView.y = itemView.y + deltaY;
   				}
   			}
   			this.addEventListener("mouseUp", backgroundDragEnd);
  		}
  		
  		private function backgroundDragEnd(event: MouseEvent):void  {
   			this.removeEventListener(MouseEvent.MOUSE_MOVE, backgroundDragContinue);
   		}
		
		private function reAllocate(source:MindMapSprite, target:MindMapSprite):void{
			if (! g.linked(source,target)){
				var father:MindMapSprite = father(source._id);
				var childs:Array = allChilds(source);
				trace("source._id: "+source._id+" target.id: "+target._id,childs);
				conn.call("reAllocate",null,source._id,target._id,childs);

			} else{
				Alert.show("they are allreadey linked");
				refreshChildNodePosition("0");
			}
		}
		
		public function reCreate(id:String, color:uint, label:String, linkId:String):void{
		    // restart 
			/*var urlRequest:URLRequest = new URLRequest(FlexGlobals.topLevelApplication.url);
			navigateToURL(urlRequest,"_top");*/
			
			/*var ref:URLRequest = new URLRequest("javascript:location.reload(true)");
			navigateToURL(ref, "_self");*/
			
/*			ExternalInterface.call("function () {window.location.reload}");
*/			/*Alert.show("recreate");
			ExternalInterface.call("window.location.reload(true)");*/

			/*ExternalInterface.call("history.go", 0);*/
			//document.getElementById('videoBox').innerHTML = '<embed ... >'
			ExternalInterface.call("recreate");
			//Alert.show("javascript:document.getElementById('"+FlexGlobals.topLevelApplication.parameters.siteName+"').innerHTML = reload");
		}
		
		public function onConnected(conn:NetConnection) : void{

			//trace("conn: " + conn);

			// guard agains null
			if(conn == null) return;
			// Set up remoteSharedObject stuff	
			
			conn.client=this;		
			so = SharedObject.getRemote("roomSO", conn.uri, false);
			so.connect(conn);
			// set the client property of the shared object to this class
            // with the help of this property the server knows in which class the 
            // called function, via so.sendMessage is located
			so.client=this;
			so.addEventListener(SyncEvent.SYNC, syncHandler); 
			synchronize();
			}
		
		/** @private */
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
   			super.updateDisplayList(unscaledWidth, unscaledHeight);
			//trace("_dataProvider != null: "+_dataProvider != null);
			//trace("_dataProvider.layoutChanged: "+_dataProvider.layoutChanged);
			if((_dataProvider != null) && _dataProvider.layoutChanged) {
				drawEdges();
				_dataProvider.layoutChanged = false;
			}
		}
		
	    /** @private */
		private function drawEdges(): void {
			drawingSurface.graphics.clear();
			var edges: Array = _dataProvider.getEdges();
			for each (var edge: GraphEdge in edges) {
				var fromNode: GraphNode = GraphNode(edge.getFrom());
				var toNode: GraphNode = GraphNode(edge.getTo());
				var fromLabel: String = GraphNode(edge.getFrom()).item.label;
				var toLabel: String = GraphNode(edge.getTo()).item.label;
				var color:uint=0x333333;
					drawEdge(fromNode.view, toNode.view, color);
				
			}
			
		}

		private function drawEdge(f: UIComponent, t: UIComponent, color: int): void {
			var fromItem: MindMapSprite = f as MindMapSprite;
			var toItem: MindMapSprite = t as MindMapSprite;
			var alpha: Number = 1.0;
			var thickness: int = 2;
			var pFrom:Point = new Point(fromItem.x + f.getChildAt(0).width, fromItem.y + (f.getChildAt(0).height >> 1));
			var pTo:Point   = new Point(toItem.x, toItem.y + (t.getChildAt(0).height >> 1));
			drawingSurface.graphics.lineStyle(thickness,color,alpha);
			drawingSurface.graphics.moveTo((pFrom.x + pTo.x) >> 1, (pFrom.y + pTo.y) >> 1);
			drawingSurface.graphics.curveTo(
				pFrom.x + ((pTo.x - pFrom.x) >> 2),
				pFrom.y,
				pFrom.x,
				pFrom.y
			);
			drawingSurface.graphics.moveTo((pFrom.x + pTo.x) >> 1, (pFrom.y + pTo.y) >> 1);
			drawingSurface.graphics.curveTo(
				pTo.x - ((pTo.x - pFrom.x) >> 2),
				pTo.y,
				pTo.x,
				pTo.y
			);	
		}	
		
		public function synchronize():void{
			conn.call("getShapeList", new Responder(getShapes, getNothing));
		}
		
		public function getShapes(obj:Object):void{
						
			var shapeList:ArrayCollection = new ArrayCollection(obj as Array);
			var innerList:Array = new Array;
			if (shapeList.length != 0) {
				for (var i:int=0; i<shapeList.length;i++){
					innerList = shapeList.getItemAt(i,0) as Array;
					var newRemoteShape:MindMapSprite = new MindMapRoundRect(innerList[0].toString(),250,20,innerList[1],innerList[2].toString());
					ballMap[newRemoteShape._id] = newRemoteShape;
					g.add(newRemoteShape);
					trace("synch newRemoteShape.id: "+newRemoteShape._id+" "+newRemoteShape.label);
					trace(newRemoteShape.hasEventListener(KeyboardEvent.KEY_DOWN));
				}
				this.dataProvider = g;
				
				for (var j:int=0; j<shapeList.length;j++){
					innerList = shapeList.getItemAt(j,0) as Array;
					trace("innerList: "+innerList);
					var source:String = innerList[0].toString();
					var sourceShape:MindMapSprite = g.find(source);
					var linkId:String = innerList[3].toString();
					var linkShape:MindMapSprite = g.find(linkId);
					trace("verbinde: "+sourceShape.label+" mit "+linkShape.label);
					g.link(sourceShape, linkShape);
					
					refreshChildNodePosition("0");
				}	this.dataProvider = g;
			}
			refreshChildNodePosition("0");
		}
		
		private function getNothing():void{
			Alert.show("no Objects on Server","getNothing");
		}	
				
		/**
		 * Traps all synchEvents that corresponds to the RSO. According to event a special case will be used.
		 * 5 events are possible, see below
		 **/ 
		private function syncHandler(event:SyncEvent):void {			
			for(var i:Object in event.changeList){
				var changeObj:Object = event.changeList[i];
				
				switch (changeObj.code){
					case "clear":
						//trace("changeObj[" + i + "].code: " + changeObj.code);
						break;
					case "reject":
						//trace("changeObj[" + i + "].code: " + changeObj.code);
						break;
					case "success":
						break;
					case "change":
					try{
						var ballId:Object = changeObj.name;
						var coordinates:Object = so.data[ballId];
						ballMap[ballId].move(coordinates.x, coordinates.y);
						refresh();
					}
					catch (typeError:TypeError){
					}
						break;
					case "delete":
						break;
						
				}
			}
		}
		/**
	    * Function to add a shape to the stage and add an value for the representation in the RSO Slot
	    * And then sends the id of the shape to the Server
	    **/
		public function newComponent(item:MindMapSprite):UIComponent {
			var component: UIComponent = item;
            
            component.y = this.height / 2;
			component.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			
			component.addEventListener(DragEvent.DRAG_ENTER, acceptDrop);
			component.addEventListener(DragEvent.DRAG_DROP, handleDrop);
			component.addEventListener(DragEvent.DRAG_OVER, dragOver);
			
			component.addEventListener(KeyboardEvent.KEY_DOWN, pressEnter);
		  
	        addComponent(item);
			return component;
            
	    }
	    
	    public function addComponent(component:MindMapSprite):void{
	    	this.addChild(component);
	    }
	    
	    public function newItem(shape:MindMapSprite):void{
	    	if (shape != null){
	    		newShape = new MindMapRoundRect(null,250,20,0xffff00,null);
	    		var selectedShape:MindMapSprite = MindMapSprite.selectedSprite;

            	ballMap[newShape._id] = newShape;
            	g.add(newShape);
            	//if(prevItem != null)
				g.link(newShape, shape);
				prevItem = newShape;
				this.dataProvider = g;
				//trace(g.father(shape)._id);
				refreshChildNodePosition("0");
				//call the server
				conn.call("newBall", null, newShape._id, newShape.color, newShape.label, shape._id, FlexGlobals.topLevelApplication.drawing_cvs.numChildren);	 
				conn.call("setShapeList", null, newShape._id, newShape.color, newShape.label, shape._id);
	    	}
	    	else Alert.show("Bitte wählen Sie einen Knoten mit der Maus aus","Kein Startknoten");
	    }
	    
	    public function addSibling(shape:MindMapSprite):void{
	    	
	    	if (shape == null) {
	    		Alert.show("Bitte wählen Sie einen Knoten mit der Maus aus","Kein Startknoten");
	    		return;
	    	}
	    	
	    	if (shape._id != "0"){
	    		var father:MindMapSprite =father(shape._id);
	    		newShape = new MindMapRoundRect(null,250,20,0xffff00,null);    
            	ballMap[newShape._id] = newShape;
            	g.add(newShape);
            	if(prevItem != null)
					g.link(newShape, father);
				prevItem = father;
				this.dataProvider = g;
				refreshChildNodePosition("0");
				conn.call("newBall", null, newShape._id, newShape.color, newShape.label, father._id, FlexGlobals.topLevelApplication.drawing_cvs.numChildren);
				conn.call("setShapeList", null, newShape._id, newShape.color, newShape.label, father._id);
	    		}
	    	else Alert.show("Der Startknoten kann keine Geschwister haben", "Error");
	    }
	    
	    public function father(id:String):MindMapSprite{
	    	//trace("father: "+id);
			var edges: Array = _dataProvider.getEdges();
				for each (var edge: GraphEdge in edges) {
					var fromNode: GraphNode = GraphNode(edge.getFrom());
					var toNode: GraphNode = GraphNode(edge.getTo());
					var fromId: String = GraphNode(edge.getFrom()).item._id;
					var toId: String = GraphNode(edge.getTo()).item._id;
					//trace("fromId: "+fromId + " toId: "+toId);
					
					var fromInt:int = parseInt(fromId);
					var toInt:int = parseInt(toId);
					
					 if (toId == id ){
						return g.find(fromId);
					}
					if (fromId == id) {
						return g.find("0");
					} 
					/* if (toId == "-1") {
						Application.application.father.text = "Der Pappa wars";
					} */
				}
	    	return null;
	    }
	    
	    
	    public function vaterKnoten(id:String): void {
			var edges: Array = _dataProvider.getEdges();
			for each (var edge: GraphEdge in edges) {
					var fromNode: GraphNode = GraphNode(edge.getFrom());
					var toNode: GraphNode = GraphNode(edge.getTo());
					var fromId: String = GraphNode(edge.getFrom()).item.label;
					var toId: String = GraphNode(edge.getTo()).item.label;
				}
				var father:MindMapSprite = fromNode.view as MindMapSprite;
		}
	    

	    
	     
	    public function allChilds(shape:MindMapSprite):Array {
			if(g.tree.length != 0){
				g.tree = [];
			}
			var childs:Array = new Array();
			childs = g.allFromSelectedChilds(shape._id);
			return childs;
	    }
	    
	    public function  get childList():ArrayCollection{
	    	var nodeList:ArrayCollection = new ArrayCollection();
	    	var childs:Array = new Array();
			childs = g.allChilds();
			for each (var id:String in childs) {
				nodeList.addItem(g.find(id));
			}
			return nodeList;
	    }
	    
	   /**
		 * Position child items.
		 */
			     
	     public function refreshChildNodePosition(id:String):void {
			var tmp:Array = new Array();
			var totalChildWidth:int = subTreeHeight(id);
			var currentY:int =  g.find(id).y - totalChildWidth / 2;
			
			tmp = g.childs(id);
			if (tmp.length != 0){
				for each (var i:String in tmp){
					var subtreeWidth:int = subTreeHeight(i);
					var shape:MindMapSprite = g.find(i);
					shape.y = currentY + subtreeWidth / 2;
					shape.x = g.father(shape).x + 260;
					refreshChildNodePosition(i);
					currentY += subtreeWidth;
				}
			} 
			drawEdges();
		}
		
		public function subTreeHeight(id:String):int {
			var tmp:Array = new Array();
			var width:int = 0;
			tmp = g.childs(id);
			if (tmp.length != 0){
				for each (var i:String in tmp){
					width += subTreeHeight(i);
				}
			} else {
				width = HEIGHT + MARGIN_BOTTOM;
			}
			return width;
		}
		
	    /**
	    * This function is called on all connected clients by the server everytime a new shape is created.
	    * It checks if the shape is already added to the stage.
	    **/
	    public function getNewRemoteShape(id:String, color:uint, label:String, linkId:String, num:int):void{
			
			//trace("getNewRemoteShape num: "+num+ " this.numChildren: "+FlexGlobals.topLevelApplication.drawing_cvs.numChildren);
			//trace(num > FlexGlobals.topLevelApplication.drawing_cvs.numChildren);
	    	if (num > FlexGlobals.topLevelApplication.drawing_cvs.numChildren){
	    		var shape:MindMapSprite = g.find(linkId);
	    		var newRemoteShape:MindMapSprite = new MindMapRoundRect(null,250,20,color,label);
	    		ballMap[newRemoteShape._id] = newRemoteShape;
            	g.add(newRemoteShape);
				g.link(newRemoteShape, shape);
				refreshChildNodePosition("0");
				this.dataProvider = g; 
				
	    	}
	    	else {
	    		//trace("getNewRemoteShape im else: "+id)
	    	}
	    }
	    
		/**
		 * Function to remove a shape from the stage
		 **/
		public function removeSubTree(shape:MindMapSprite):void{
			var childs:Array = allChilds(shape);;
			if (childs != null){
				for(var i:int=0;i<childs.length;i++){
					var j:String = childs[i];
					var temp:MindMapSprite = g.find(j);
					remove(temp);
				}
			}
			remove(shape);
			
		}
		
	    /**
	    * Function to remove a shape from the stage
	    **/
	    public function remove(shape:MindMapSprite):void{
			if (shape._id == "0"){
				return;
			}
			var index:int = this.getChildIndex(shape);
			var father:MindMapSprite =father(shape._id);
			conn.call("deleteShape", null, shape._id, shape.color,shape.label,father._id, FlexGlobals.topLevelApplication.drawing_cvs.numChildren);
			g.remove(shape);
			//removeChildAt(index);
			ballMap[shape._id] = null;
			refreshChildNodePosition("0");
			MindMapSprite.selectedSprite=null;
		}
		
		
		public function deleteRemoteShape(id:String, number:int):void{
			if(number <= FlexGlobals.topLevelApplication.drawing_cvs.numChildren){
				var shape:MindMapSprite = g.find(id);
				g.remove(shape);
				refreshChildNodePosition("0");
				//this.removeChildAt(id);
			}	
		}
		
		public function removeComponent(component: UIComponent): void {
 			//Object(component).removeYourself();
 			
	 			component.parent.removeChild(component);
  		}
  		
  		
  		public function changeShape(id:String,color:int, label:String, nummer:Number):void{
			var shape:MindMapSprite = g.find(id);
			shape.label = label;
			shape.color = color;
			var index:int = this.getChildIndex(shape);
			trace("changeSHape: "+label+" "+color);
			shape.drawShape();
		}
  		
 		
		
		public function set dataProvider(obj: Object): void {
			setDataProvider(obj);
		}
		
		public function get dataProvider(): Object {
			return _graph;
		}
		
		private function setDataProvider(obj: Object): void {
			if(creationIsComplete) {
				doSetDataProvider(obj);
			} else {
				pendingDataProvider = obj;
			}
		}
		
		private var creationIsComplete: Boolean = false;
		private var pendingDataProvider: Object = null;
		
		private function doSetDataProvider(obj: Object): void {
			/* if(obj is XML)
				obj = Graph.fromXML(obj as XML, _xmlNames); */
			_graph = obj as Graph;
			//trace("_graph: "+_graph);
			rebuild();
			g.addEventListener(Graph.CHANGE, graphChangeHandler);
		}
		
		public function graphChangeHandler(event: Event): void {
			rebuild();
		}
		
		private function rebuild(): void {
			if((_graph != null) && (_dataProvider != null)) {
	   	        _dataProvider.graph = _graph;
				refresh();
				
			}
		}
		
		 public function refresh(): void {
        	//trace("refresh");
        	if(_dataProvider != null) {
	        	_dataProvider.layoutChanged = true;
	        	invalidateDisplayList();
	        }
        }
        
        private function myCreationComplete(event: Object): void {
 			creationIsComplete = true;
 			//trace("creationIsComplete: "+creationIsComplete);
 			
 			if(pendingDataProvider != null) {
 				doSetDataProvider(pendingDataProvider);
 				pendingDataProvider = null;
 			}
 			rebuild();
 		}
 		
 		private function myPreinitialize(event: Object): void {
			BindingUtils.bindSetter(onConnected, this, "conn");
			var dp: GraphDataProvider = new GraphDataProvider(this);
			_dataProvider = dp;
			this.dataProvider = g;
	 		}

 		
 		public function saveToXML():void {
 			conn.call( "saveToXML", new Responder(onSuccess, onFault));	
 		}
 		
 		private function onSuccess(obj:Object):void{
 			Alert.show("Saving was successfull ", "save");
 		}
 		
 		private function onFault(obj:Object):void{
 			Alert.show("Error","fault");
 		}
		
	

		
	}
}